package com.tool.spring.manager;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author: lixiaofei
 */
@Slf4j
public class SecurityHandler implements InvocationHandler {
    private Object targetObject;

    public  Object newProxy(Object targetObject){
        this.targetObject=targetObject;
        return Proxy.newProxyInstance(targetObject.getClass().getClassLoader(),
                targetObject.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        checkSecurity();
        Object result=null;
        try {
            result = method.invoke(this.targetObject, args);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    //执行的动作的具体实现
    public void checkSecurity(){
        log.info("----security----");
    }
}
